#include <bits/stdc++.h>

using namespace std;
const int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dy[] = {0, -1, -1, -1, 0, 1, 1, 1};
class Solution {
   public:
    void gameOfLife(vector<vector<int>>& board) {
        vector<vector<int>> tmp(board);
        for (int i = 0; i < board.size(); ++i) {
            for (int j = 0; j < board[i].size(); ++j) {
                int count = 0;
                for (int k = 0; k < 8; ++k) {
                    if (i + dx[k] >= 0 && i + dx[k] < board.size() &&
                        j + dy[k] >= 0 && j + dy[k] < board[i].size() &&
                        tmp[i + dx[k]][j + dy[k]] == 1) {
                        count++;
                    }
                }
                if (board[i][j] == 1) {
                    if (count == 2 || count == 3) {
                    } else {
                        board[i][j] = 0;
                    }
                } else if (count == 3) {
                    board[i][j] = 1;
                }
            }
        }
    }
};